<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2020/7/19
  Time: 13:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String basePath = request.getScheme()
            +"://"
            +request.getServerName()
            + ":"
            +request.getServerPort()
            +request.getContextPath()
            +"/";
%>
<html>
<head>
    <base href="<%=basePath%>">
    <title>投票</title>
    <script type="text/javascript" src="${pageContext.request.contextPath}/webjars/jquery/3.5.1/jquery.min.js"></script>
    <script>
        $(function() {
            $("#sub_btn").click(function () {
                if(${sessionScope.judge.status==1}){
                    $("span.errorMsg").text("你已经投过票了或已弃权!");
                    return false;
                }
            });
        });
    </script>
</head>
<body>
<c:if test="${empty sessionScope.judge}">
    <a href="../login.jsp">请登录</a>
</c:if>
<c:if test="${not empty sessionScope.judge}">
<h1>投票项目Id:${sessionScope.vote.voteId}</h1>
<div>投票描述:</div>
<br>
<div>${sessionScope.vote.name}</div>
<h1>
    请投票:
</h1>
<form action="voteServlet" method="post">
    <input type="hidden" name="action" id="action" value="castVote"/>
<table>
<c:forEach items="${sessionScope.candidates}" var="entry">
    <tr>
        <td>
            <input type="radio" name="candidateId" id="${entry.candidateId}" value="${entry.candidateId}"/>${entry.name}
        </td>
    </tr>
</c:forEach>
    <tr>
        <td>
            <input type="submit" value="投票" tabindex="1" id="sub_btn"/>
        </td>
    </tr>
</table>
</form>
    <a href="voteServlet?action=giveUp">弃权</a>
    <br>
    <a href="userServlet?action=logout">登出</a>
    <br>
<span class="errorMsg">
    ${sessionScope.msg}
    </span>
</c:if>
</body>
</html>
